#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> getGoodIndices(vector<vector<int>>& variables, int target) {
        vector<int> ret;
        for (int i = 0; i < variables.size(); i++)
        {
            int a = variables[i][0];
            int b = variables[i][1];
            int c = variables[i][2];
            int m = variables[i][3];
            int sum_1 = 1;
            while (b--)
            {
                sum_1 %= 10;
                sum_1 *= a;
            }
            sum_1 %= 10;
            int sum_2 = 1;
            while (c--)
            {
                sum_2 %= m;
                sum_2 *= sum_1;
            }
            sum_2 %= m;
            if (sum_2 == target)
            {
                ret.push_back(i);
            }
        }
        return ret;
    }
};